
//=============================================================================================
// Implementation of Exposure Fusion
//
// This work is described in
//   "Exposure Fusion"
//   Tom Mertens, Jan Kautz and Frank Van Reeth
//   In Proceedings of Pacific Graphics 2007
//
// written by Kuen-Shiou Tsai, July 2013
// e-mail: kuenbutsai@gmail.com
//=============================================================================================

#include "expo_fusion.h"

#define INPUT_IMAGE		0
#define INPUT_VIDEO		1
#define INPUT_CAMERA	2

int main()
{
	int input = INPUT_CAMERA;

	if(input == INPUT_IMAGE)
	{
		Mat src = imread("C:/Users/kuenbutsai/Desktop/dataset/src.bmp");
		imshow("src", src);

		clock_t t0 = clock();

		expo_fusion fusion;
		fusion.process(src);

		clock_t tf = clock();
		printf("total %d\n",tf-t0);

		imshow("recon", fusion.recon);

		imwrite("C:/Users/kuenbutsai/Desktop/result.bmp", fusion.recon);

		waitKey(0);
	}
	//=============================================================================
	else if(input == INPUT_VIDEO)
	{
		VideoCapture vc("C:/Users/kuenbutsai/Desktop/1.mp4");

		expo_fusion fusion;
		Mat src;

		while(1)
		{		
			vc >>src;
			if(src.empty())
				break;

			imshow("src", src);
			imwrite("C:/Users/kuenbutsai/Desktop/src.bmp", src);

			clock_t t0 = clock();

			fusion.process(src);

			clock_t tf = clock();
			printf("total %d\n",tf-t0);

			imshow("recon", fusion.recon);
			imwrite("C:/Users/kuenbutsai/Desktop/result.bmp", fusion.recon);

			waitKey(80);
		}
	}
	else if(input == INPUT_CAMERA)
	{
		VideoCapture vc(0);

		expo_fusion fusion;
		Mat src;

		while(1)
		{
			vc >>src;

			imshow("src", src);
			//imwrite("C:/Users/kuenbutsai/Desktop/src.bmp", src);

			clock_t t0 = clock();

			fusion.process(src);

			clock_t tf = clock();
			printf("total %d\n",tf-t0);

			imshow("recon", fusion.recon);
			//imwrite("C:/Users/kuenbutsai/Desktop/result.bmp", fusion.recon);

			waitKey(1);
		}
	}

	return 0;
}